﻿
//Sorting an array means to arrange its elements in increasing order.
//Write a program to sort an array. Use the "selection sort" algorithm:
//Find the smallest element, move it at the first position,
//find the smallest from the rest, move it at the second position, etc.
// az sym pe6o
using System;

class SelectionSort
{
    static void Main()
    {
        Random rand = new Random();

        int[] array = new int[15];

        for (int i = 0; i < array.Length; i++)
        {
            array[i] = rand.Next(-10000, 10000);
        }

        DisplArray(array);


        MySort(array);
        Console.WriteLine();
        DisplArray(array);
    }

    private static void MySort(int[] array)
    {
        for (int i = 0; i < array.Length; i++)
        {
            int temp = array[i];
            int pos = i;
            for (int j = i + 1; j < array.Length; j++)
            {
                if (temp > array[j])
                {
                    temp = array[j];
                    pos = j;
                }
            }

            array[pos] = array[i];
            array[i] = temp;
        }
    }

    private static void DisplArray(int[] array)
    {
        for (int i = 0; i < array.Length; i++)
        {
            Console.Write("{0}; ", array[i]);
        }
    }
}